package com.ciwong.epaper.modules.me.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.me.bean.MaterialBean;
import com.ciwong.libs.utils.CWLog;

import java.util.ArrayList;
import java.util.List;

import static android.support.v7.widget.RecyclerView.Adapter;
import static android.support.v7.widget.RecyclerView.ViewHolder;
import static android.view.View.OnClickListener;

public class CheckPublishDialogAdapter extends Adapter {

    private Context mContext;
    private LayoutInflater factory;
    private List<MaterialBean> list = new ArrayList<>();

    public CheckPublishDialogAdapter(Context context) {
        this.mContext = context;
        factory = LayoutInflater.from(context);
    }

    public void setData(List<MaterialBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    private OnItemClickListener onItemClickListener;

    public interface OnItemClickListener {

        void onItemClick(ViewHolder holder, List<MaterialBean> list, int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ViewHolder viewHolder = null;
        View inflate = factory.inflate(R.layout.item_dialog_publish, parent, false);
        viewHolder = new CalatogViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
        MaterialBean materialBean = list.get(position);
        ((TextView)holder.itemView).setText(materialBean.getVersionName());
        CWLog.d("CheckPublishDialogAdapter:",materialBean.getVersionName());
        holder.itemView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null)
                    onItemClickListener.onItemClick(holder, list, position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    public class CalatogViewHolder extends ViewHolder {
        public CalatogViewHolder(View itemView) {
            super(itemView);
        }
    }
}
